package com.woniuxy.mapper;

import com.woniuxy.provider.LogsProvider;
import com.work.framework.pojo.Logs;
import org.apache.ibatis.annotations.*;
import org.springframework.jdbc.core.SqlProvider;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * 〈日志查询mapper〉
 *
 * @author mjh
 * @create 2019/9/20
 */

@Mapper
@Repository
public interface LogMapper {

    //查所有
    @Select("select * from logs where flag = 1")
    @Results(value = {
            @Result(id = true,property = "id",column = "id"),
            @Result(property = "operation_time",column = "operation_time"),
            @Result(property = "operator",column = "operator"),
            @Result(property = "operation_description",column = "operation_description")
    })
     List<Logs> findAll();

    //模糊查询
    @SelectProvider(type = LogsProvider.class,method = "providerSql")
    @Results(value = {
            @Result(id = true,property = "id",column = "id"),
            @Result(property = "operation_time",column = "operation_time"),
            @Result(property = "operator",column = "operator"),
            @Result(property = "operation_description",column = "operation_description")
    })
    List<Logs> findByLike(Logs logs);

    @Insert("INSERT INTO `logs` \n" +
            "( `operation_time`, `operator`, `operation_description`, `module`, `response`, `ip`, `result`) \n" +
            "VALUES (#{operation_time},#{operator},#{operation_description},#{module},#{response},#{ip},#{result} )")
    @Results(value = {
            @Result(id = true,property = "id",column = "id"),
            @Result(property = "operation_time",column = "operation_time"),
            @Result(property = "operator",column = "operator"),
            @Result(property = "operation_description",column = "operation_description")
    })
    int insertLogs(Logs logs);

}
